<?php
/**
 * Created by PhpStorm.
 * User: linzh
 * Date: 2017-05-10
 * Time: 13:46
 */

namespace application\module\explorer\controller;

use ReflectionClass;

abstract class base
{

    public $in;
    public $db;
    public $config;    // 全局配置
    public $tpl;    // 模板目录
    public $values;    // 模板变量
    public $L;

    /**
     * 构造函数
     */
    function __construct()
    {
        global $in, $config, $db, $L;

        $this->db = $db;
        $this->L = $L;
        $this->config = &$config;
        $this->in = &$in;
        $this->values['config'] = &$config;
        $this->values['in'] = &$in;
    }


    /**
     * 加载类库文件
     * @param string $class
     */
    public function loadClass($class)
    {
        if (1 === func_num_args()) {
            $this->$class = new $class;
        } else {
            $reflectionObj = new ReflectionClass($class);
            $args = func_get_args();
            array_shift($args);
            $this->$class = $reflectionObj->newInstanceArgs($args);
        }
        return $this->$class;
    }

    /**
     * 显示模板
     * @param $key
     * @param $value
     * @return void
     */
    protected function assign($key, $value)
    {
        $this->values[$key] = $value;
    }

    /**
     * 显示模板
     * @param
     */
    protected function display($tpl_file)
    {
        global $L, $LNG;
        extract($this->values);
        require($this->tpl . $tpl_file);
    }
}
